package com.rankeiot.developer.domain;

import com.rankeiot.core.data.Kv;
import lombok.Data;
import lombok.experimental.FieldNameConstants;
import org.sagacity.sqltoy.config.annotation.Column;
import org.sagacity.sqltoy.config.annotation.Entity;
import org.sagacity.sqltoy.config.annotation.Id;
import org.sagacity.sqltoy.config.model.*;

import java.io.Serializable;
import java.sql.Types;
import java.util.*;


@Entity(tableName="t_table_meta")
@FieldNameConstants(asEnum = true)
@Data
public class TableMeta  implements Serializable {
    public static final String TABLE="t_table_meta";
    @Id
    @Column(name = "id", length = 20L, type = Types.VARCHAR, nullable = false,comment = "ID")
    private String id;


    @Column(name = "data_source", length = 20L, type = Types.VARCHAR, nullable = false,comment = "数据源")
    private String dataSource;

    @Column(name = "db_type", length = 20L, type = Types.VARCHAR, nullable = false,comment = "数据库那些")
    //数据库类型
    private String dbType;

    /**
     * 表名
     */
    @Column(name = "table_name", length = 20L, type = Types.VARCHAR, nullable = false,comment = "表名")
    private String tableName;

    /**
     * 建表语句
     */
    @Column(name = "ddl",length = 200L,type = Types.VARCHAR,nullable = true,comment = "建表语句")
    private String ddl;

    /**
     * 字段名称对应字段信息的hashMap, 便于通过名称获取字段信息(长度、类型、默认值等等)
     */
    @Column(name = "fields_meta", length = 1024L, type = Types.CLOB, nullable = false,comment = "表字段")
    private List<TableFieldMeta> fieldsMeta = new ArrayList<>();


    /**
     * id产生策略
     */
    @Column(name = "id_strategy", length = 10L, type = Types.VARCHAR, nullable = true,comment = "主键策略")
    private PKStrategy idStrategy=PKStrategy.IDENTITY;

    @Column(name = "load_sql", length = 100L, type = Types.VARCHAR, nullable = true,comment = "查询语句")
    /**
     * 根据主键load查询的sql
     */
    private String loadSql;

    /**
     * 获取所有记录sql
     */
    @Column(name = "load_all_sql", length = 100L, type = Types.VARCHAR, nullable = true,comment = "查询全部语句")
    private String loadAllSql;


//    /**
//     * 加密字段
//     */
//    private List<FieldSecureConfig> secureFields = new ArrayList<FieldSecureConfig>();
//
//    /**
//     * 加解密字段
//     */
//    private IgnoreCaseSet secureColumns;

    @Column(name = "index_models", length = 100L, type = Types.VARCHAR, nullable = true,comment = "索引")
    /**
     * 数据库表索引信息
     */
    private IndexModel[] indexModels;

    /**======== 前端属性=============****/
    @Column(name = "title", length = 100L, type = Types.VARCHAR, nullable = true,comment = "表标题")
    private String title;

    //目录名 对应到编辑器里面的目录名字
    @Column(name = "dir_name", length = 50L, type = Types.VARCHAR, nullable = true,comment = "目录名")
    private String dirName;
    //目录路径 对应到编辑器里面的目录路径
    @Column(name = "dir_path", length = 50L, type = Types.VARCHAR, nullable = true,comment = "目录路径")
    private String dirPath;

    @Column(name = "memo", length = 50L, type = Types.VARCHAR, nullable = true,comment = "表说明")
    private String memo;
    @Column(name = "view_groups", length = 100L, type = Types.VARCHAR, nullable = true,comment = "显示的分组信息")
    //显示分组
    private List<Kv> viewGroups=null;

    @Column(name = "form_model", length = 10L, type = Types.VARCHAR, nullable = true,comment = "表单显示模式")
    //表单模式(几列)
    private String formModel="single";

    //权限定义,为空表示对应不需要权限
    @Column(name = "auth_list", length = 50L, type = Types.VARCHAR, nullable = true,comment = "列表权限")
    private String authList;
    @Column(name = "auth_create", length = 50L, type = Types.VARCHAR, nullable = true,comment = "创建权限")
    private String authCreate;
    @Column(name = "auth_delete", length = 50L, type = Types.VARCHAR, nullable = true,comment = "删除权限")
    private String authDelete;
    @Column(name = "auth_modify", length = 50L, type = Types.VARCHAR, nullable = true,comment = "修改权限")
    private String authModify;

    @Column(name = "role_list", length = 50L, type = Types.VARCHAR, nullable = true,comment = "列表角色")
    private String roleList;
    @Column(name = "role_create", length = 50L, type = Types.VARCHAR, nullable = true,comment = "创建角色")
    private String roleCreate;
    @Column(name = "role_delete", length = 50L, type = Types.VARCHAR, nullable = true,comment = "删除角色")
    private String roleDelete;
    @Column(name = "role_modify", length = 50L, type = Types.VARCHAR, nullable = true,comment = "修改角色")
    private String roleModify;

    //对应API路径,为空表默认
    @Column(name = "list_api", length = 50L, type = Types.VARCHAR, nullable = true,comment = "列表接口")
    private String listApi;
    @Column(name = "detail_api", length = 50L, type = Types.VARCHAR, nullable = true,comment = "详情接口")
    private String detailApi;
    @Column(name = "save_api", length = 50L, type = Types.VARCHAR, nullable = true,comment = "保存接口")
    private String saveApi;
    @Column(name = "delete_api", length = 50L, type = Types.VARCHAR, nullable = true,comment = "删除接口")
    private String deleteApi;

    @Column(name = "page_url", length = 50L, type = Types.VARCHAR, nullable = true,comment = "页面地址")
    private String pageUrl;

    @Column(name = "enable", length = 1L, type = Types.TINYINT, nullable = true,comment = "是否启用")
    private boolean enable;

    @Column(name = "crate_time", length = 50L, type = Types.TIMESTAMP, nullable = false,defaultValue = "CURRENT_TIMESTAMP",comment = "创建时间")
    private Date crateTime;
    @Column(name = "create_user", length = 50L, type = Types.VARCHAR, nullable = false,comment = "创建人")
    private String createUser;

    public TableMeta(){

    }
    public TableMeta(String id){
        this.id=id;
    }
}
